package com.test.daily.leetcode.y2022.m05.day0522.v02;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/5/22 下午 03:59
 * @version: 1.0
 */
public class Solution {
    public static class Node{
        int value;
        Node left;
        Node right;
        public Node(int value){
            this.value = value;
        }
    }
    public static void main(String[] args) {

    }
    public static void printInOrder(Node head, int height, String flag, int len){
        if(head == null){
            return;
        }
        // 1.先打印左树节点
        printInOrder(head.left, height + 1, "^", len);
        // 2. 打印当前节点
        String value = flag + head.value + flag;
        int lenL = ((height - value.length())>>1);
        int lenM = value.length();
        int lenR = len - lenL - lenM;
        value = getSpace(lenL) + value + getSpace(lenR);
        System.out.println(getSpace(height*len) + value);
        // 3.最后打印右树节点
        printInOrder(head.right, height + 1, "v", len);

    }
    public static String getSpace(int spaceL){
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < spaceL; i++) {
            stringBuffer.append(" ");
        }
        return stringBuffer.toString();
    }
}
